#
# Name:    makefile
# Creates: tinyxml static lib: libtinyxml.a
# Usage:   make -f makefile
#

# To install /usr/local/lib/tinyxml/libtinyxml.a and /usr/local/include/tinyxml/*.h, type:
#    make install

TARGET=libtinyxml.a
TARGET_INSTALL_DIR = /usr/local
TARGET_INSTALL_SUBDIR = tinyxml

VERSION_INFO=$(shell svnversion)

# Source dir list
source_dirs := ./src 

CC = g++
AR = ar

EXTRA_IPATHS = -I/usr/local/include

CFLAGS       = $(EXTRA_CFLAGS) -O2 -ggdb3 -Wall -Wshadow -rdynamic
DEFLIST      = $(EXTRA_DEFLIST) -DLINUX -DTIXML_USE_STL -D_FILE_OFFSET_BITS=64
IPATHS       = $(EXTRA_IPATHS) -I./include
LPATHS       = $(EXTRA_LPATHS)

libdir = ${TARGET_INSTALL_DIR}/lib
includedir = ${TARGET_INSTALL_DIR}/include
targetlibdir = $(libdir)/$(TARGET_INSTALL_SUBDIR)
targetincdir = $(includedir)/$(TARGET_INSTALL_SUBDIR)

VPATH   := $(source_dirs)

search_wildcard  := $(addsuffix /*.cpp,$(source_dirs))

$(TARGET): $(notdir $(patsubst   %.cpp,%.o,$(wildcard   $(search_wildcard))))
	@echo Linking $@
	@$(AR) -cr $@ $^
	@echo Done.

%.o: %.cpp
	@echo Compiling $<
	@$(CC) $(CFLAGS) $(DEFLIST) $(IPATHS) $(LFLAGS) -c -MD $(addprefix -I ,$(source_dirs)) $<
include $(wildcard   *.d)

all: $(TARGET)

this: $(TARGET)

install: $(TARGET)
	-@if [ ! -d $(TARGET_INSTALL_DIR) ]; then mkdir -p $(TARGET_INSTALL_DIR); fi
	-@if [ ! -d $(includedir)  ]; then mkdir -p $(includedir); fi
	-@if [ ! -d $(libdir)      ]; then mkdir -p $(libdir); fi
	-@if [ ! -d $(targetlibdir)  ]; then mkdir -p $(targetlibdir); fi
	-@if [ ! -d $(targetincdir)  ]; then mkdir -p $(targetincdir); fi

	cp -rf include/* $(targetincdir)
	rm -rf $(targetincdir)/CVS
	chmod 644 $(targetincdir)/*.h
	cp $(TARGET) $(targetlibdir)
	cd $(targetlibdir); chmod 755 $(TARGET)

clean: 
	rm  -f *.o
	rm  -f *.d
	rm  -f $(TARGET)

version:
	@echo $(VERSION_INFO)

update:
	@svn up $(SVN_PARAMS)

